##Title:Main Analysis
##Date: 26 Sept 2023

```{r preparation}
library(tidyverse)

library(plm)
library(modelsummary)

dat <- read.csv("D:/Essex_PhD/3rd_year/Data for R&R/Replication_R1_20240918/replication_20231015.csv") 
unique(dat$gwno)
```


```{r  peacekeeping and aid models}
dat_check <- dat  %>%
  as.data.frame() %>%
  group_by( gid) %>%
  mutate(lag_treat_pko = dplyr::lag(treat_pko),
         lag_treat_aid = dplyr::lag(treat_aid),
         lag_osv = dplyr::lag(osv))


model1.1 <- plm(treat_pko ~ lag_treat_aid + lag_osv, 
                         data = dat_check,
                         index = c("gid", "year"), model = "within")
model1.2 <- plm(treat_pko ~ lag_treat_aid + lag_osv + 
                 lncapdist + lnbdist + ttime_mean  + 
                 lnpop + mountains_mean + prec_gpcp + imr_mean + conflict_intensity + 
                 spatial_lag_osv + spatial_lag_pko +
                 task_tamm + humaid_assist_tamm, 
                         data = dat_check,
                         index = c("gid", "year"), model = "within")
model2.1 <- plm(treat_aid ~ lag_treat_pko + lag_osv, 
                         data = dat_check,
                         index = c("gid", "year"), model = "within")
model2.2 <- plm(treat_aid ~ lag_treat_pko + lag_osv + 
                 lncapdist + lnbdist + ttime_mean  + 
                 lnpop + mountains_mean + prec_gpcp + imr_mean + conflict_intensity + 
                 spatial_lag_osv + spatial_lag_pko +
                 task_tamm + humaid_assist_tamm, 
                         data = dat_check,
                         index = c("gid", "year"), model = "within")

modelsummary(list(model1.1, model1.2, 
                  model2.1, model2.2), stars = TRUE)
```

